﻿using Heima.OA.IBLL;
using Heima.OA.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heima.OA.BLL
{
    public partial class ActionInfoService : BaseService<ActionInfo>, IActionInfoService
    {
        public bool SetRole(int actionId, List<int> roleIds)
        {
            //GetEntities(u => u.Id == id).FirstOrDefault();
            var action = DbSession.ActionInfoDal.GetModel(actionId);
            action.RoleInfo.Clear();//删除权限所有的角色关系
            var allRoles = DbSession.RoleInfoDal.GetEntities(r => roleIds.Contains(r.Id));
            foreach (var role in allRoles)
            {
                action.RoleInfo.Add(role);//权限添加最新的角色关系
            }
            return DbSession.SaveChanges() > 0;
        }

    }
}
